<!-- stories/templates/stories/my_stories.html -->
{% extends 'stories/base.html' %}
{% load static %}

{% block title %}我的故事 - AI故事生成网站{% endblock %}

{% block content %}
<div class="container">
    <div class="page-header">
        <h1>我的故事</h1>
        <div class="page-actions">
            <a href="{% url 'stories:ai_story_generator' %}" class="btn btn-primary">+ 新建故事</a>
        </div>
    </div>

    {% if stories %}
        <div class="my-stories-list">
            {% for story in stories %}
                <div class="story-item">
                    <div class="story-left">
                        <div class="story-cover">
                            {% if story.cover_image %}
                                <img src="{{ story.cover_image.url }}" alt="{{ story.title }}">
                            {% else %}
                                <div class="cover-text">{{ story.title|slice:":8" }}</div>
                            {% endif %}
                        </div>
                        {% if story.status == 'pending' %}
                            <!-- 审核中状态提示 -->
                            <div class="status-pending">审核中</div>
                        {% endif %}
                    </div>
                    <div class="story-info">
                        <h3><a href="{% url 'stories:story_detail' story.id %}">{{ story.title }}</a></h3>
                        <div class="story-meta">
                            <span class="category">{{ story.category.name }}</span>
                            <span class="date">创建于: {{ story.created_at|date:"Y-m-d H:i" }}</span>
                            {% if story.status == 'published' %}
                                <span class="views">👁️ {{ story.view_count }}</span>
                                <span class="rating">
                                    <span class="star-rating">
                                        {% for i in "12345" %}
                                            {% if forloop.counter <= story.average_rating|floatformat:0 %}
                                                ★
                                            {% else %}
                                                ☆
                                            {% endif %}
                                        {% endfor %}
                                    </span>
                                    ({{ story.rating_count }})
                                </span>
                            {% endif %}
                        </div>
                        <p class="story-excerpt">{{ story.content|truncatewords:30 }}</p>
                        <div class="story-actions">
                            {% if story.status == 'pending' %}
                                <!-- 审核中状态，不显示编辑按钮 -->
                                <a href="{% url 'stories:story_detail' story.id %}" class="btn btn-sm btn-view">预览</a>
                            {% elif story.status == 'published' %}
                                <!-- 已发布状态，不显示编辑按钮 -->
                                <a href="{% url 'stories:story_detail' story.id %}" class="btn btn-sm btn-view">查看</a>
                            {% else %}
                                <!-- 草稿和被驳回状态，显示编辑按钮 -->
                                <a href="{% url 'stories:edit_story' story.id %}" class="btn btn-sm btn-edit">编辑</a>
                                {% if story.status == 'draft' or story.status == 'rejected' %}
                                    <!-- 草稿和被驳回的故事可以提交审核 -->
                                    <form method="post" action="{% url 'stories:edit_story' story.id %}" style="display: inline;">
                                        {% csrf_token %}
                                        <button type="submit" name="submit_for_review" class="btn btn-sm btn-publish" onclick="return confirm('确定要提交审核吗？')">提交审核</button>
                                    </form>
                                {% endif %}
                                <a href="{% url 'stories:story_detail' story.id %}" class="btn btn-sm btn-view">预览</a>
                            {% endif %}
                        </div>
                    </div>
                </div>
            {% endfor %}
        </div>
    {% else %}
        <div class="no-stories">
            <p>您还没有创建任何故事</p>
            <a href="{% url 'stories:ai_story_generator' %}" class="btn btn-primary">立即创作第一个故事</a>
        </div>
    {% endif %}
</div>
{% endblock %}